package com.wom.blockfeatures;

import com.wom.blocks.AbstractBlock;
import com.wom.blocks.AirBlock;
import com.wom.blocks.WaterBlock;
import com.wom.gui.BlockTypes;
import com.wom.worldmaker.GameWorld;

public class LiquidBlock {

	private int fluidTime=0;
	private int maxTime=0;
	private int flowAmount=-1;

	
	public LiquidBlock(int max ){
		
		//setFlowAmount(amount);
		setMaxTime(max);
	}


	public void flowLeft(AbstractBlock b){

		if(BlockUtils.getBlockLeft(b) instanceof AirBlock){
		GameWorld.gameBlocks[b.getxPos()-1][b.getyPos()]=new WaterBlock(b.getxPos()-1,b.getyPos());
		}

	}
	
	public void flowRight(AbstractBlock b){

		if(BlockUtils.getBlockRight(b) instanceof AirBlock){
		GameWorld.gameBlocks[b.getxPos()+1][b.getyPos()]=new WaterBlock(b.getxPos()+1,b.getyPos());
		}

	}

	public void flowDown(AbstractBlock b){

		if(BlockUtils.getBlockBelow(b) instanceof AirBlock){
		GameWorld.gameBlocks[b.getxPos()][b.getyPos()+1]=new WaterBlock(b.getxPos(),b.getyPos()+1);
		}




	}
	
	public void fullFlow(AbstractBlock b){
		
		if(getFluidTime()>=getMaxTime()){

			setFluidTime(0);

			if(!BlockUtils.isIsolatedBlock(b, BlockTypes.air)){
		
				flowLeft(b);
				flowRight(b);
				flowDown(b);
		}
			

			//GameWorld.player.mousePressedRight=false;
		}else{
			setFluidTime(getFluidTime()+1);
			
		}

		
		
	}


	public int getFluidTime() {
		return fluidTime;
	}


	public void setFluidTime(int fluidTime) {
		this.fluidTime = fluidTime;
	}


	public int getFlowAmount() {
		return flowAmount;
	}


	public void setFlowAmount(int flowAmount) {
		this.flowAmount = flowAmount;
	}


	public int getMaxTime() {
		return maxTime;
	}


	public void setMaxTime(int maxTime) {
		this.maxTime = maxTime;
	}
	
	


}
